package com.benin.sms.extend

import android.Manifest
import android.content.Context
import android.content.pm.PackageManager
import android.util.Log
import androidx.core.content.ContextCompat


fun Context.isAgreeLaunchPermissions(): Boolean {
    try {
        if (PackageManager.PERMISSION_GRANTED != ContextCompat.checkSelfPermission(
                this,
                Manifest.permission.READ_CONTACTS
            )
        ) {
            Log.d(this::class.java.simpleName, "checkPermissions: READ_CONTACTS")
            return false
        }
//        if (PackageManager.PERMISSION_GRANTED != ContextCompat.checkSelfPermission(
//                this,
//                Manifest.permission.CAMERA
//            )
//        ) {
//            Log.d(this::class.java.simpleName, "checkPermissions: CAMERA")
//            return false
//        }
        if (PackageManager.PERMISSION_GRANTED != ContextCompat.checkSelfPermission(
                this,
                Manifest.permission.ACCESS_COARSE_LOCATION
            )
        ) {
            Log.d(this::class.java.simpleName, "checkPermissions: ACCESS_COARSE_LOCATION")
            return false
        }
        if (PackageManager.PERMISSION_GRANTED != ContextCompat.checkSelfPermission(
                this,
                Manifest.permission.ACCESS_FINE_LOCATION
            )
        ) {
            Log.d(this::class.java.simpleName, "checkPermissions: ACCESS_FINE_LOCATION")
            return false
        }
        if (PackageManager.PERMISSION_GRANTED != ContextCompat.checkSelfPermission(
                this,
                Manifest.permission.WRITE_EXTERNAL_STORAGE
            )
        ) {
            Log.d(this::class.java.simpleName, "checkPermissions: WRITE_EXTERNAL_STORAGE")
            return false
        }
        if (PackageManager.PERMISSION_GRANTED != ContextCompat.checkSelfPermission(
                this,
                Manifest.permission.READ_EXTERNAL_STORAGE
            )
        ) {
            Log.d(this::class.java.simpleName, "checkPermissions: READ_EXTERNAL_STORAGE")
            return false
        }
//        if (PackageManager.PERMISSION_GRANTED != ContextCompat.checkSelfPermission(
//                this,
//                Manifest.permission.READ_SMS
//            )
//        ) {
//            Log.d(this::class.java.simpleName, "checkPermissions: READ_SMS")
//            return false
//        }
        if (PackageManager.PERMISSION_GRANTED != ContextCompat.checkSelfPermission(
                this,
                Manifest.permission.READ_PHONE_STATE
            )
        ) {
            Log.d(this::class.java.simpleName, "checkPermissions: READ_PHONE_STATE")
            return false
        }
//        if (PackageManager.PERMISSION_GRANTED != ContextCompat.checkSelfPermission(
//                this,
//                Manifest.permission.READ_CALENDAR
//            )
//        ) {
//            Log.d(this::class.java.simpleName, "checkPermissions: READ_CALENDAR")
//            return false
//        }
//        if (PackageManager.PERMISSION_GRANTED != ContextCompat.checkSelfPermission(
//                this,
//                Manifest.permission.GET_ACCOUNTS
//            )
//        ) {
//            Log.d(this::class.java.simpleName, "checkPermissions: GET_ACCOUNTS")
//            return false
//        }
//        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
//            return PackageManager.PERMISSION_GRANTED == ContextCompat.checkSelfPermission(
//                this,
//                Manifest.permission.ACCESS_MEDIA_LOCATION
//            )
//        }

        if (PackageManager.PERMISSION_GRANTED != ContextCompat.checkSelfPermission(
                this,
                Manifest.permission.READ_LOGS
            )
        ) {
            Log.d(this::class.java.simpleName, "checkPermissions: READ_LOGS")
            return false
        }
    } catch (e: Exception) {
        e.printStackTrace()
    }
    return true
}